package com.whmnx.main.ui.activity;

import android.os.Bundle;
import android.text.TextUtils;

import androidx.fragment.app.Fragment;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.google.android.material.tabs.TabLayout;
import com.whmnx.base.router.RouterActivityPath;
import com.whmnx.main.R;
import com.whmnx.main.databinding.FragmentCommodityDetailsBinding;
import com.whmnx.main.ui.adapter.BaseFragmentPagerAdapter;
import com.whmnx.main.ui.fragment.CommentFragment;
import com.whmnx.main.ui.fragment.ProShouMinFragment;
import com.whmnx.main.ui.model.ComDetailsModel;

import java.util.ArrayList;
import java.util.List;

import io.reactivex.disposables.Disposable;
import me.goldze.mvvmhabit.BR;
import me.goldze.mvvmhabit.base.BaseActivity;
import me.goldze.mvvmhabit.utils.SPUtils;

/**
 * author : huang
 * date   : 2020/10/13 0013 18:12
 * version: 1.0
 * @author Administrator
 */
@Route(path = RouterActivityPath.Main.ORDER)
public class CommodityDetailsActivity extends BaseActivity<FragmentCommodityDetailsBinding, ComDetailsModel> {

    private Disposable subscribe;
    private String product_id;
    public ProShouMinFragment proShouMinFragment;
    public CommentFragment commentFragment;

    @Override
    public int initContentView(Bundle savedInstanceState) {
        return R.layout.fragment_commodity_details;
    }

    @Override
    public int initVariableId() {
        return BR.viewModel;
    }

    @Override
    public void initData() {
        super.initData();
        product_id = getIntent().getStringExtra("Product_Id");
        if(TextUtils.isEmpty(product_id)){
            product_id =  SPUtils.getInstance().getString("Product_Id");
        }

        viewModel.initToolbar(this,binding,product_id);
        List<Fragment> list = new ArrayList<>();
        proShouMinFragment = new ProShouMinFragment();
        commentFragment = new CommentFragment();
        Bundle bundle = new Bundle();
        bundle.putString("product_id", product_id);
        commentFragment.setArguments(bundle);
        list.add(proShouMinFragment);
        list.add(commentFragment);



        List<String> list2 = new ArrayList<>();
        list2.add("商品说明");
        list2.add("评论");

        //设置Adapter
        BaseFragmentPagerAdapter pagerAdapter = new BaseFragmentPagerAdapter(getSupportFragmentManager(), list, list2);
        binding.viewPager.setAdapter(pagerAdapter);
        binding.tabs.setupWithViewPager(binding.viewPager);
        binding.viewPager.addOnPageChangeListener(new TabLayout.TabLayoutOnPageChangeListener(binding.tabs));
        viewModel.initToolbar(this,binding,product_id);

    }
}
